﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using POSSystem.DAL;

namespace POSSystem.BLL
{
    public class AttachedFiles : _AttachedFiles
    {
        public class FileCategory
        {
            public const int CustomerRequest = 1;
        }

        public static void AddAttachFile(int ownerObject, int category, string filename, string path)
        {
            try
            {
                AttachedFiles f = new AttachedFiles();
                f.AddNew();
                f.OwnerObjectID = ownerObject;
                f.Category = category;
                f.FileName = filename;
                f.Path = path;
                f.Save();
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("AttachedFiles.cs", "AddAttachFile", ex.StackTrace);
                throw ex;
            }
        }

        public void AttachFile(int ownerObject, int category, string filename, string path)
        {
            try
            {
                this.AddNew();
                this.OwnerObjectID = ownerObject;
                this.Category = category;
                this.FileName = filename;
                this.Path = path;
                this.Deleted = false;
                this.CreatedDate = DateTime.UtcNow.AddHours(SystemVariables.SysVars.TimeZone);
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("AttachedFiles.cs", "AttachFile", ex.StackTrace);
                throw ex;
            }
        }

        public static AttachedFiles GetFiles(int ownerID, int category)
        {
            try
            {
                AttachedFiles files = new AttachedFiles();
                files.Where.OwnerObjectID.Value = ownerID;
                files.Where.Category.Value = category;
                files.Query.Load();

                return files;
            }
            catch (Exception ex)
            {
                ErrorLog.WriteToFile("AttachedFiles.cs", "GetFiles", ex.StackTrace);
                throw ex;
            }
        }
    }
}
